import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

import org.apache.lucene.queryparser.flexible.standard.QueryParserUtil;


//public static void
public class QueryFileReader
{
	// Class variables
	private File mFileName;
	public Map<Integer,String> mQueries;
	
	/**
	 * Class constructor
	 * @param fileName The query file name
	 * @throws NumberFormatException
	 * @throws IOException
	 */
	public QueryFileReader(String fileName) throws NumberFormatException, IOException
	{
		// Method variables
		String line;
		mQueries = new HashMap<Integer,String>();
		mFileName = new File(fileName);
		FileInputStream fileInputStream = new FileInputStream(mFileName);			
		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));
		
		// Read the file line by line
		while ((line = bufferedReader.readLine()) != null) 
		{
			String[] parts = line.split(" ", 2);
			Integer id = Integer.parseInt(parts[0].trim());
			String query = parts[1].trim(); 
			query = QueryParserUtil.escape(query);
			query  = query.replaceAll("-"," ");
			mQueries.put(id, query);
		}			
		bufferedReader.close();
	}
}